package com.reef.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.reef.entity.Reader;
@Component
public class LoginInterceptor implements HandlerInterceptor{
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println();
	}
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println();
	}
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//获取到session
		HttpSession session = request.getSession();
		//获取到session在controller存储的内容属性
		Reader rea = (Reader) session.getAttribute("list");
		if (rea== null) {
			//request.getRequestDispatcher("/views/user/login.html").forward(request, response);
			response.sendRedirect("/views/user/login.html");
			return false;
		}else {
			return true;
		}
	}
}
